﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CEntidades;
using System.Data;
using System.Data.SqlClient;

namespace CDatos{
    public class dCategoria{
        public static List<eCategoria> ListarCategorias(){
            List<eCategoria> Lista = null;
            SqlCommand cmd = null;
            SqlDataReader dr = null;
            try{
                Conexion cn = new Conexion();
                SqlConnection conex = cn.conectar();
                cmd = new SqlCommand("uspListarCategorias", conex);
                cmd.CommandType = CommandType.StoredProcedure;
                conex.Open();
                dr = cmd.ExecuteReader();
                Lista = new List<eCategoria>();
                while (dr.Read()){
                    eCategoria c = new eCategoria();
                    c.IdCategoria= Convert.ToInt32(dr["IdCategoria"]);
                    c.Descripcion= dr["Descripcion"].ToString();
                    Lista.Add(c);
                }
            }catch{
                Lista = null;
            }finally{
                cmd.Connection.Close();
            }
            return Lista;
        }


    }
}
